<?php
require_once("xforms/Core.php");

class XForms_secret extends XForms_core {
  protected $tpl = '<div class="xforms_secret {renderClass}">{renderHelp} {renderRequired} {renderLabel}<br /><input type="password" {renderAttributes} {renderValue} {renderReadOnly}  /><br /><div class="xforms_validationmessage xforms_nonvisible"></div>{renderHint}</div>';
  protected $script = '.append(new XForms_secret({renderJson}))';
  
  function renderClass(){
  $cssClass="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("relevant")) {
	$xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("relevant")){
	  case true: break;
      case false: $cssClass=$cssClass . " xforms_nonvisible";break;
      default:
    }
	
  }
  return $cssClass;
  }

 
  function renderReadOnly(){
  $readonly="";
  $binding = $this->getBinding();
  if($binding) {
	$xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("readonly")){
      case true: $readonly= 'readonly="readonly"'; break;
      case false: break;
      default:
    }
  }
  return $readonly;
}

 
  function renderRequired(){
   $binding = $this->getBinding();
   $required="";
   if($binding){
	$xBinding = $this->getXElement($binding);
	if($xBinding->evalAttribute("required"))
     $required =  $required . '<b style="color:red"> * </b>';
  return $required;
   }
  }
  function renderLabel(){
 	return $this->renderChildNodes(array("xforms:label"));

  }
  
  function renderHelp(){
    return $this->renderChildNodes(array("xforms:help"));
  }
  function renderHint(){
    return $this->renderChildNodes(array("xforms:hint"));
  }
  function renderValue(){
    return ' value="'.htmlentities($this->getValue(), ENT_QUOTES, 'utf-8').'"';
  }
  }
